package lesson07.threadpool;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 功能描述
 *
 * @author wileda
 * @date 2023/01/15  12:49
 */
public class Demo06 {
    public static void main(String[] args) {
        ThreadPoolExecutor  threadPoolExecutor = new ThreadPoolExecutor(
                5,//核心线程数
                10,//最大线程数
                1,//临时线程存活的时间
                TimeUnit.SECONDS,//时间单位
                new LinkedBlockingQueue<>(20),//阻塞队列类型
                new ThreadPoolExecutor.DiscardOldestPolicy()) {//拒绝策略
                };
        for (int i = 0; i < 100; i++) {
            int  taskId = i;
            threadPoolExecutor.submit(() -> {
                System.out.println("线程" + taskId + " " +Thread.currentThread().getName());
            });
        }
    }
}
